package daily.may0510;

import java.util.ArrayList;
import java.util.Collection;

public class GenericWildcardAdvancedUsageTest {
    public static void main(String[] args) {
        Collection<Integer> list_1 = new ArrayList<>();
        Collection<String> list_2 = new ArrayList<>();
        Collection<Number> list_3 = new ArrayList<>();
        Collection<Object> list_4 = new ArrayList<>();

        getElement_1(list_1);
        //getElement_1(list_2);//报错，String类不是Number类的子类
        getElement_1(list_3);
        //getElement_1(list_4);//报错，Object类不是Number类的子类

        //getElement_2(list_1);//报错，Integer类不是Number类的父类
        //getElement_2(list_2);//报错，String类不是Number类的父类
        getElement_2(list_3);
        getElement_2(list_4);

    }
    //泛型的上限：此时的泛型?，必须是Number类型或者Number类型的子类
    public static void getElement_1(Collection<? extends Number> collection) {
        System.out.println(collection);
    }
    //泛型的下限：此时的泛型?，必须是Number类型或者Number类型的父类
    public static void getElement_2(Collection<? super Number> collection){
        System.out.println(collection);
    }
}
